home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / KEYSTATE.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  3KB  |  76 lines

  1. @echo off
  2. REM ******************************************************
  3. REM *** KeyState - Macro to set, unset, or display the ***
  4. REM *** ver.1      state of keys NUMLOCK, CAPSLOCK or  ***
  5. REM ***            SCROLL keys.                        ***
  6. REM ******************************************************
  7.  
  8. cenvi %0.bat %1 %2 %3 %4
  9. GOTO CENVI_EXIT
  10.  
  11. #define  NUMLOCK_BIT    0x20
  12. #define  CAPSLOCK_BIT   0x40
  13. #define  INSERT_BIT     0x80
  14. #define  KEYS_SEGMENT   0x0040
  15. #define  KEYS_OFFSET    0x0017
  16. KeysAddress = Address(KEYS_SEGMENT,KEYS_OFFSET)
  17.  
  18. main(argc,argv)
  19. {
  20.    // check that the input is valid
  21.    if ( argc != 3
  22.      || ( argv[1][1] != 0  ||  !strchr("+?-",argv[1][0]) )
  23.      || ( strnicmp("CAP",argv[2],3)
  24.        && strnicmp("NUM",argv[2],3)
  25.        && strnicmp("INS",argv[2],3) ) ) {
  26.       Instructions()
  27.    } else {
  28.       // determine whether to apply to CapsLock or NumLock
  29.       if ( !strnicmp("CAP",argv[2],3) ) {
  30.          KeyName = "CapsLock", KeyBit = CAPSLOCK_BIT
  31.       }
  32.       else if ( !strnicmp("NUM",argv[2],3) ) {
  33.          KeyName = "NumLock",  KeyBit = NUMLOCK_BIT
  34.       } else {
  35.          KeyName = "Insert",   KeyBit = INSERT_BIT
  36.       }
  37.       // perform action on the selected key
  38.       CurrentState = peek(KeysAddress)
  39.       switch( argv[1][0] ) {
  40.          case '+':   // Set Key ON
  41.             poke(KeysAddress,CurrentState | KeyBit)
  42.             break
  43.          case '-':   // Turn KEY OFF
  44.             poke(KeysAddress,CurrentState & ~KeyBit)
  45.             break
  46.          case '?':   // display and return state of key
  47.             printf("%s is currently set %s.\n",KeyName,CurrentState & KeyBit ? "ON" : "OFF")
  48.             return( CurrentState & KeyBit ? 1 : 0 )
  49.       }
  50.    }
  51. }
  52.  
  53.  
  54. Instructions()
  55. {
  56.    printf("\a\n")
  57.    printf("KeyState - Set, Clear, or Show the keyboard state of NumLock or CapsLock\n");
  58.    printf("\n");
  59.    printf("SYNTAX: KeyState < + | - | ? > < CAP | NUM | INS >\n");
  60.    printf("\n");
  61.    printf("Where:  +    Set KeyState ON\n");
  62.    printf("        -    Set KeySTate OFF\n");
  63.    printf("        ?    Display current Key State, and return ERRORLEVEL 1 if set\n");
  64.    printf("             and ERRORLEVEL 0 if clear\n");
  65.    printf("        NUM  Apply command < + | - | ? > to the NumLock key\n");
  66.    printf("        CAP  Apply command < + | - | ? > to the CapsLock key\n");
  67.    printf("        INS  Apply command < + | - | ? > to the Insert key\n");
  68.    printf("\n");
  69.    printf("Examples: KeyState + Num      Turn on the Numlock key\n");
  70.    printf("          KeyState - Cap      Turn of the CapsLock key\n");
  71.    printf("          KeyState ? Num      Show state of NumLock, return ERRORLEVEL if set\n");
  72.    printf("\n")
  73. }
  74.  
  75. :CENVI_EXIT
  76.